package com.jk.sec.controller;

import com.jk.DiscussBean;
import com.jk.LookBean;
import com.jk.MovieBean;
import com.jk.UserBean;
import com.jk.service.SecUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.util.List;


@Controller
@RequestMapping("buy")
public class SecMovieController {


    @Autowired
    private HttpSession session;

    @Autowired
    private SecUserService secUserService;

        /**
         * @Author: 孙尔超
         * @Description: 查询
         * @Date: 2021/6/7 22:43
         * @Return: java.lang.Double
         **/
    @RequestMapping("star")
    @ResponseBody
    public Double star(Integer ids){
        return secUserService.star(ids);
    }


    /**
     * @Author: 孙尔超
     * @Description:影片详情
     * @Date: 2021/5/21 10:29
     * @param ids
     * @param model
     * @Return: com.jk.MovieBean
     **/
    @GetMapping("ticket")
    public String ticket(Integer ids, Model model){
        MovieBean movie=secUserService.ticket(ids);
        model.addAttribute("movie",movie);
        return "comment/comment";
    }
    /**
     * @Author: 孙尔超
     * @Description: 我的短评
     * @Date: 2021/5/21 15:08
     * @Return: com.jk.DiscussBean
     **/
    @PostMapping("discuss")
    @ResponseBody
    public void discuss(String content,Integer ids,Integer star){
        UserBean user = (UserBean) session.getAttribute("user");

        secUserService.discuss(content,ids,user,star);
    }

    /**
     * @Author: 孙尔超
     * @Description: 查看所有评论
     * @Date: 2021/5/21 16:10
     * @Return: java.util.List<com.jk.DiscussBean>
     **/
    @RequestMapping("findDiscuss")
    @ResponseBody
    public List<DiscussBean> findDiscuss(Integer ids){
        return secUserService.findDiscuss(ids);
    }

    /**
     * @Author: 孙尔超
     * @Description: 点赞
     * @Date: 2021/5/23 19:07
     * @param ids
     * @param give
     * @Return: void
     **/
    @RequestMapping("like")
    @ResponseBody
    public void like(String ids,Integer give,String id){
        UserBean user = (UserBean) session.getAttribute("user");
        secUserService.like(ids,give,id,user);
    }

    /**
     * @Author: 孙尔超
     * @Description: 查询票房榜单
     * @Date: 2021/5/23 19:08
     * @Return: java.util.List<com.jk.MovieBean>
     **/
    @RequestMapping("monthlyFocus")
    @ResponseBody
    @Scheduled(cron ="0 0 8 * * ?")
    public List<MovieBean> monthlyFocus(){
        List<MovieBean> list=secUserService.monthlyFocus();
        return list;
    }
    /**
     * @Author: 孙尔超
     * @Description: 想看人数
     * @Date: 2021/5/23 21:37
     * @Return: java.util.List<com.jk.MovieBean>
     **/
    @RequestMapping("expect")
    @ResponseBody
    @Scheduled(cron ="0 0 8 * * ?")
    public List<MovieBean> expect(){
        List<MovieBean> list=secUserService.expect();
        return list;
    }


/**
 * @Author: 孙尔超
 * @Description: 票房排序
 * @Date: 2021/5/23 21:44
 * @Return: java.util.List<com.jk.MovieBean>
 **/
    @RequestMapping("boxoffice")
    @ResponseBody
    @Scheduled(cron ="0 0 8 * * ?")
    public List<MovieBean> boxoffice(){
        List<MovieBean> list=secUserService.boxoffice();
        return list;
    }
    /**
     * @Author: 孙尔超
     * @Description: 查询电影的所有演员
     * @Date: 2021/5/25 15:14
     * @param ids
     * @Return: java.util.List<com.jk.MovieBean>
     **/
    @RequestMapping("findActor")
    @ResponseBody
    public List<MovieBean> findActor(Integer ids){
        return secUserService.findActor(ids);
    }

    /**
     * @Author: 孙尔超
     * @Description: 查询评分的总条数
     * @Date: 2021/5/25 16:31
     * @Return: java.lang.String
     **/
    @RequestMapping("scorecount")
    @ResponseBody
    public Integer scorecount(Integer ids){
       Integer count= secUserService.scorecount(ids);
        return count;
    }
    /**
     * @Author: 孙尔超
     * @Description: 查询相关电影
     * @Date: 2021/6/6 21:05
     * @Return: java.util.List<com.jk.MovieBean>
     **/
    @RequestMapping("relatedMovie")
    @ResponseBody
    public List<MovieBean> relatedMovie(String typeid){
        return secUserService.relatedMovie(typeid);
    }
    /*
     * @Author: 孙尔超
     * @Description: 上映电影
     * @Date: 2021/6/7 16:07
     * @Return: void
     **/
    @RequestMapping("show")
    @ResponseBody
    @Scheduled(cron ="0 0 0 * * ?")
    public void show() throws ParseException {
        secUserService.show();
    }

    /**
     * @Author: 孙尔超
     * @Description: 点击想看
     * @Date: 2021/6/8 10:53
     * @param
     * @Return:
     **/
    @RequestMapping("havaLook")
    @ResponseBody
    public LookBean havaLook(Integer ids){
        UserBean user = (UserBean) session.getAttribute("user");
            return secUserService.havaLook(ids,user);
    }
        /**
         * @Author: 孙尔超
         * @Description: 想看点击
         * @Date: 2021/6/8 11:40
         * @Return: void
         **/
    @RequestMapping("loveLook")
    @ResponseBody
    public void loveLook(Integer ids){
        UserBean user = (UserBean) session.getAttribute("user");
        secUserService.loveLook(ids,user);
    }
        /**
         * @Author: 孙尔超
         * @Description: 已想看点击
         * @Date: 2021/6/8 11:40
         * @Return: void
         **/
    @RequestMapping("loveLooks")
    @ResponseBody
    public void loveLooks(Integer ids){
        UserBean user = (UserBean) session.getAttribute("user");
        secUserService.loveLooks(ids,user);
    }

}
